package com.huarun.module.timer;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Component;

/**
 * @author dzm
 * @创建时间 2018-11-02 18:02
 * @Description 类描述
 * 
 */
@Configuration
@EnableScheduling
@Component
public class SchedulerListener {
	@Autowired
	public SchedulerAllJob myScheduler;

	@Bean
	public SchedulerFactoryBean schedulerFactoryBean() {
		SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
		return schedulerFactoryBean;
	}

	// 开机启动
	@Bean(destroyMethod = "shutdown")
	public Executor taskSchedulerJob() {
		try {
			myScheduler.scheduleDayJobs();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Executors.newScheduledThreadPool(3);
	}
}
